using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using UserManagementService.Common.DTOs;

namespace UserManagementService.Organizations;

/// <summary>
/// 组织仓储接口
/// </summary>
public interface IOrganizationRepository : IRepository<Organization, Guid>
{
    /// <summary>
    /// 根据编码获取组织
    /// </summary>
    Task<Organization?> GetByCodeAsync(
        string code,
        bool includeDetails = true,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取根组织
    /// </summary>
    Task<List<Organization>> GetRootOrganizationsAsync(
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取子组织
    /// </summary>
    Task<List<Organization>> GetChildrenAsync(
        Guid parentId,
        bool includeDetails = false,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取组织树
    /// </summary>
    Task<List<Organization>> GetOrganizationTreeAsync(
        Guid? rootId = null,
        bool includeMembers = false,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 检查编码是否重复
    /// </summary>
    Task<bool> IsCodeExistAsync(
        string code,
        Guid? excludeId = null,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取组织成员
    /// </summary>
    Task<List<OrganizationMember>> GetMembersAsync(
        Guid organizationId,
        bool includeUserDetails = false,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取用户所属组织
    /// </summary>
    Task<List<Organization>> GetUserOrganizationsAsync(
        Guid userId,
        bool includeDetails = false,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 移动组织
    /// </summary>
    Task MoveOrganizationAsync(
        Guid organizationId,
        Guid? newParentId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 获取组织统计信息
    /// </summary>
    Task<OrganizationStatisticsDto> GetStatisticsAsync(
        Guid? organizationId = null,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 搜索组织
    /// </summary>
    Task<List<Organization>> SearchOrganizationsAsync(
        string keyword,
        int maxResultCount = 10,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// 批量更新组织状态
    /// </summary>
    Task<int> BatchUpdateStatusAsync(
        List<Guid> organizationIds,
        bool isEnabled,
        CancellationToken cancellationToken = default);
}